package hhh.app.presenter.model.productdetail;

import java.util.List;

import javax.inject.Inject;
import javax.inject.Named;

import hhh.app.data.bean.Product;
import hhh.app.data.bean.ProductDiscount;
import hhh.app.data.bean.ProductImage;
import hhh.app.data.bean.ProductOption;
import hhh.app.data.bean.Review;
import hhh.app.domain.interactor.GetProductDetail;
import hhh.app.domain.interactor.GetProductDiscounts;
import hhh.app.domain.interactor.GetProductImages;
import hhh.app.domain.interactor.GetProductOptions;
import hhh.app.domain.interactor.GetProductReview;
import hhh.app.domain.interactor.ProductCase;
import hhh.app.presenter.ui.base.BasePresenter;
import hhh.app.presenter.ui.base.MySubscriber;

/**
 * Created by hhh on 2016/10/31.
 */
public class ProductDetailPresenter extends BasePresenter<ProductDetailContract.IProductDetailView> implements ProductDetailContract.IProductDetailPresenter{
    private GetProductDetail getProductDetail;
    private GetProductDiscounts getProductDiscounts;
    private GetProductImages getProductImages;
    private GetProductOptions getProductOptions;
    private GetProductReview getProductReview;

    @Inject
    public ProductDetailPresenter(@Named("productDetail") ProductCase getProductDetail,
                                  @Named("productDiscounts") ProductCase getProductDiscounts,
                                  @Named("productImages") ProductCase getProductImages,
                                  @Named("productOptions") ProductCase getProductOptions,
                                  @Named("productReview") ProductCase getProductReview
                                        ) {
        if(getProductDetail instanceof GetProductDetail){
            this.getProductDetail=(GetProductDetail)getProductDetail;
        }
        if(getProductDiscounts instanceof GetProductDiscounts){
            this.getProductDiscounts=(GetProductDiscounts) getProductDiscounts;
        }
        if(getProductImages instanceof GetProductImages){
            this.getProductImages=(GetProductImages) getProductImages;
        }
        if(getProductOptions instanceof GetProductDetail){
            this.getProductOptions=(GetProductOptions) getProductOptions;
        }
        if(getProductReview instanceof GetProductReview){
            this.getProductReview= (GetProductReview) getProductReview;
        }
    }

    @Override
    public void loadProduct(int pid) {
        if(getProductDetail!=null){
            getProductDetail.setPid(pid).execute(new MySubscriber<Product>() {
                @Override
                public void onNext(Product product) {

                }
            });
        }
    }

    @Override
    public void loadProductImages(int pid) {
        if(getProductImages!=null){
            getProductImages.setProductId(pid).execute(new MySubscriber<List<ProductImage>>() {
                @Override
                public void onNext(List<ProductImage> productImages) {
                    if(productImages!=null) {
                        view.showProductImages(productImages);
                    }
                }
            });
        }
    }

    @Override
    public void loadProductDiscounts(int pid) {
        if(getProductDiscounts!=null){
            getProductDiscounts.setProductId(pid).execute(new MySubscriber<List<ProductDiscount>>() {
                @Override
                public void onNext(List<ProductDiscount> productDiscounts) {
                    if(productDiscounts!=null) {
                        view.showProductDiscounts(productDiscounts);
                    }
                }
            });
        }
    }

    @Override
    public void loadProductOptions(int pid) {
        if(getProductOptions!=null){
            getProductOptions.setProductId(pid).execute(new MySubscriber<List<ProductOption>>() {
                @Override
                public void onNext(List<ProductOption> productOptions) {
                    if(productOptions!=null) {
                        view.showProductOptions(productOptions);
                    }
                }
            });
        }
    }

    @Override
    public void loadProductReviews(int pid) {
        if(getProductReview!=null){
            getProductReview.setPid(pid).execute(new MySubscriber<List<Review>>() {
                @Override
                public void onNext(List<Review> reviews) {
                    if(reviews!=null) {
                        view.showProductReviews(reviews);
                    }
                }
            });
        }
    }
}
